
package net.biaji.alephclient;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 * 一本书的抽象
 * 
 * @author biAji<biaji@biaji.net>
 */
final public class Book {
    /**
     * 预订
     */
    public static final int BOOK_STATUS_ORDERED = 2;

    /**
     * 架上
     */
    public static final int BOOK_STATUS_INLIB = 0;

    /**
     * 已借
     */
    public static final int BOOK_STATUS_INHAND = 1;

    /**
     * 过期
     */
    public static final int BOOK_STATUS_TIMEOUT = 4;

    public static final int EXPIRE_DATE = 30;

    /**
     * 系统号，用以定位单一书目。对用户不可见
     */
    private String SN;

    /**
     * 续借代码。此代码由借阅书籍页面中的checkbox获取。
     */
    private String extendCode;

    /**
     * 索书号
     */
    private String standardNum;

    private String ISBN;

    private String name;

    private String otherName;

    private String mediaType;

    private ArrayList<String> authors = new ArrayList<String>();

    private String pubDate;

    private Date lendDate;

    private Date returnDateExpected;

    private Date returnDate;

    private float fine;

    private String coverUrl;

    private String describe;

    private String publisher;

    private String price;

    /**
     * 获得系统号
     * 
     * @return
     */
    public String getSN() {
        return SN;
    }

    /**
     * 设置系统号
     * 
     * @param sN
     */
    public void setSN(String sN) {
        SN = sN;
    }

    /**
     * 获得索书号
     * 
     * @return
     */
    public String getStandardNum() {
        return standardNum;
    }

    /**
     * 设置索书号
     * 
     * @param standNum
     */
    public void setStandardNum(String standNum) {
        this.standardNum = standNum;
    }

    public String getISBN() {
        return ISBN;
    }

    public void setISBN(String iSBN) {
        ISBN = iSBN;
    }

    /**
     * 获取书名
     * 
     * @return 书的名称
     */
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getOtherName() {
        return otherName;
    }

    public void setOtherName(String otherName) {
        this.otherName = otherName;
    }

    public String getMediaType() {
        return mediaType;
    }

    public void setMediaType(String mediaType) {
        this.mediaType = mediaType;
    }

    /**
     * 获取作者，多个作者暂时放入同一字串表示
     * 
     * @return
     */
    public ArrayList<String> getAuthor() {
        return authors;
    }

    /**
     * 以字符串形式获取作者
     * 
     * @return
     */
    public String getAuthorStr() {
        StringBuilder result = new StringBuilder();
        for (String author : authors) {
            result.append(author).append(" ");
        }
        return result.toString();
    }

    public void setAuthors(ArrayList<String> authors) {
        this.authors = authors;
    }

    public void setAuthors(String authors) {
        for (String author : authors.split(" ")) {
            addAuthor(author);
        }
    }

    public void addAuthor(String author) {
        this.authors.add(author);
    }

    public String getPubDate() {
        return pubDate;
    }

    public void setPubDate(String pubDate) {
        this.pubDate = pubDate;
    }

    public Date getBorrowDate() {
        return lendDate;
    }

    public void setBorrowDate(Date borrowDate) {
        this.lendDate = borrowDate;
    }

    public Date getReturnDate() {
        return returnDate;
    }

    public void setReturnDate(Date returnDate) {
        this.returnDate = returnDate;
    }

    public void setReturnDate(String returnDate) {
        try {
            this.returnDate = new SimpleDateFormat("MM/dd/yyyy").parse(returnDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    /**
     * 应还日期
     * 
     * @return
     */
    public Date getReturnDateExpected() {
        return returnDateExpected;
    }

    public void setReturnDateExpected(Date returnDateExpected) {
        this.returnDateExpected = returnDateExpected;
    }

    public void setReturnDateExpected(String returnDateExpectedStr) {
        try {
            this.returnDateExpected = new SimpleDateFormat("MM/dd/yyyy")
                    .parse(returnDateExpectedStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    public float getFine() {
        return fine;
    }

    public void setFine(float fine) {
        this.fine = fine;
    }

    public String getCoverUrl() {
        return coverUrl;
    }

    public void setCoverUrl(String coverUrl) {
        this.coverUrl = coverUrl;
    }

    /**
     * 获得书籍描述
     * 
     * @return
     */
    public String getDescribe() {
        return describe;
    }

    /**
     * 设置书籍描述
     * 
     * @param describe
     */
    public void setDescribe(String describe) {
        this.describe = describe;
    }

    /**
     * 获取出版商
     * 
     * @return
     */
    public String getPublisher() {
        return publisher;
    }

    /**
     * 设置出版商
     * 
     * @param publisher
     */
    public void setPublisher(String publisher) {
        this.publisher = publisher;
    }

    /**
     * 获取价格，暂以字符串表示
     * 
     * @return
     */
    public String getPrice() {
        return price;
    }

    /**
     * 设置价格
     * 
     * @param price
     */
    public void setPrice(String price) {
        this.price = price;
    }

    public String getExtendCode() {
        return extendCode;
    }

    public void setExtendCode(String extendCode) {
        this.extendCode = extendCode;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("Name:").append(name).append("\n");
        sb.append("SN:").append(SN).append("\n");
        sb.append("StandardNum:").append(standardNum).append("\n");
        sb.append("Author:");
        for (String author : authors) {
            sb.append(" ").append(author).append("\n");
        }
        sb.append("PubDate:").append(pubDate).append("\n");
        return sb.toString();
    }

}
